from django.db import models

# Create your models here.
# 产品表
class Product(models.Model):
    name = models.CharField(max_length=30, verbose_name='产品名称')
    num = models.IntegerField()
    img = models.ImageField(upload_to='uploads')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'product'


# 订单表
class Orders(models.Model):
    name = models.CharField(max_length=30, verbose_name='收货人')
    dates = models.DateTimeField(auto_now_add=True)
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='订单价格')
    num = models.IntegerField()
    details = models.CharField(max_length=200)
    product = models.ForeignKey(to="Product",on_delete=models.CASCADE,null=True,blank=True)


    def __str__(self):
        return self.name

    class Meta:
        db_table = 'orders'

# 用户表
class Users(models.Model):
    name = models.CharField(max_length=30, verbose_name='用户名')
    password = models.CharField(max_length=200)
    is_admin = models.CharField(max_length=30,default=0)
    product = models.ForeignKey(to="Product", on_delete=models.CASCADE, null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'users'

# 详情表
class Details(models.Model):
    name = models.CharField(max_length=30, verbose_name='详情内容')
    product = models.ForeignKey(to="Product", on_delete=models.CASCADE, null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'details'